package com.swang.pms.service.manage.impl;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.swang.pms.dal.ManageLogDao;
import com.swang.pms.model.common.GridUtil;
import com.swang.pms.model.common.Pager;
import com.swang.pms.model.dto.PlfLogDto;
import com.swang.pms.model.entity.PlfLog;
import com.swang.pms.service.manage.ManageLogService;

/**
 * @ClassName: ManageLogServiceImpl
 * @Description: 日志服务实现类
 * @author 王泽
 * @date 2017年3月16日 下午9:45:51
 */
@Service("manageLogService")
public class ManageLogServiceImpl implements ManageLogService {

    @Resource
    private ManageLogDao manageLogDao;

    @Override
    public int batchInsert(List<PlfLog> logs) {
        return this.manageLogDao.batchInsert(logs);
    }

    @Override
    public Pager findPageGrid(Pager page, PlfLogDto dto) {
        String[] paramSerial = new String[] { "id", "operator", "request_params", "content", "class_name", "method_name", "url",
                "client_ip", "gmt_create", "elapsed_time" };
        dto.setColumns(Arrays.asList(paramSerial).toString().replaceAll("[\\[\\]\\s]", ""));
        dto.setStartIndex(page.getRowStartIndex());
        dto.setPageSize(page.getPageSize());
        List<Map<String, Object>> list = this.manageLogDao.findPageDataByDto(dto);

        dto.setStartIndex(null);
        dto.setPageSize(null);
        page.setRowCount(this.manageLogDao.findPageDataCountByDto(dto));
        page.setGridr(GridUtil.getGridList(list, paramSerial, page.getRowStartIndex(), page.getPageSize(), page.getRowCount(), true));
        return page;
    }

}
